package edu.wuster.blog.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/*
* 前后端跨域请求控制
* */

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**") // 映射路径
                .allowedOrigins("http://localhost:3000","http://localhost:3001") //前端占用的端口
                .allowedMethods("GET", "POST","PUT","DELETE") // 允许的HTTP方法
                .allowedHeaders("*") // 允许的HTTP头部
                .allowCredentials(true); // 是否允许发送Cookie
    }
}
